<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class User_man_model extends CI_Model {

	function __construct()
	{
		parent::__construct();
		$this->CI = get_instance();
	}
	
	function insert_user($data){
		$this->db->insert('users',$data);
	}
	
	function get_user_man_grid(){	
		$this->db->select('*');
		$this->db->from('users');
		$this->db->join('role','role.IDROLE = users.IDROLE');
		$this->db->join('tb_master_sekolah','tb_master_sekolah.ID_SEKOLAH = users.ID_SEKOLAH');
		$this->db->where("users.STATUS > 0 ");
		if($this->session->userdata('roleid')!='0')
			$this->db->where("users.IDROLE != 0 ");
		$this->CI->flexigrid->build_query();
		
		$return['records'] = $this->db->get();
		
		$this->db->select('*');
		$this->db->from('users');
		$this->db->join('role','role.IDROLE = users.IDROLE');
		$this->db->join('tb_master_sekolah','tb_master_sekolah.ID_SEKOLAH = users.ID_SEKOLAH');
		$this->db->where("users.STATUS > 0 ");
		if($this->session->userdata('roleid')!='0')
			$this->db->where("users.IDROLE != 0 ");
		$this->CI->flexigrid->build_query(FALSE);
		
		$return['record_count'] = $this->db->count_all_results();

		return $return;
	}
	
	function delete_user($id_user){
		$data = array(
			'STATUS' 			=> 0
		);
		$this->db->where('ID_USER',$id_user);
		$this->db->update('users',$data);
	}
	
	function get_userID($id_user){
		$this->db->select('*');
		$this->db->from('users');
		$this->db->join('role','role.IDROLE = users.IDROLE');
		$this->db->where('ID_USER',$id_user);
		$query = $this->db->get();
		return $query;
	}
	
	function get_role(){
		$this->db->select("*");
		$this->db->from('role');
		$this->db->where("STATUS > 0 ");
		$this->db->where("IDROLE > 0 ");
		$this->db->order_by('IDROLE');
		$query = $this->db->get();
		return $query;
	}
	
	function update_user($data,$id_user){
		$this->db->where('ID_USER',$id_user);
		$this->db->update('users',$data);
	}
	
	function get_user(){
		$this->db->select("users.*,ID_TA,ID_SMT");
		$this->db->from('users');
		$this->db->join('tb_master_tahun_ajaran','tb_master_tahun_ajaran.ID_SEKOLAH = users.ID_SEKOLAH');
		$this->db->join('tb_master_semester','tb_master_semester.ID_SEKOLAH = users.ID_SEKOLAH');
		$this->db->where("tb_master_tahun_ajaran.ISAKTIF > 0 ");
		$this->db->where("tb_master_semester.ISAKTIF > 0 ");
		$this->db->where("STATUS > 0 ");
		$query = $this->db->get();
		return $query;
	}
	
	function get_menteri(){
		$this->db->select('*');
		$this->db->from('users');
		$this->db->where('STATUS = 2');
		$query = $this->db->get();
		return $query;
	}
	
}

?>